<script src="../../../../Users/Administrator/Desktop/市场部/source/heater/js/index.js"></script>
<template>
  <div>
    <div class="bg" @click="hideMenu"></div>
    <div class="moban">

      <a class="back" @click="deviceReady">
        <div class="backicon"></div>
      </a><a style="margin-top: 5px" class="more" @click="showMenu" >
      <img src="../..//static/img/more.png" /></a>
      <span class="moban_title">小管家智能照明</span>
      <div class="xiala" >
        <a @click="toAbout">品牌介绍</a>
        <a class="devicelist">设备管理</a>
      </div>
      <!--<div class="xiala">-->
        <!--<a href="#">-->
          <!--<img src="../../static/img/jiantou.png" />关于我们</a><a href="#"><img src="../../static/img/jiantou.png" />-->
        <!--设备管理</a>-->
      <!--</div>-->
    </div>
    <div class="disable"></div>
    <span  class="none"></span>
    <div class="top">
      <span id="trigger2" class="iconfont icon-dingshi dingshiguanji "></span>
      <h1 class="thetitle"></h1>
    </div>
    <div class="main" style="background-image:url(static/img/bg.png);">
      <div class="box ">
        <span id="icon"></span>
        <div class="box_bg"></div>
        <div class="zhuti" style="background-image:url(static/img/bai.png);">
          <div class="zhuti_huang" style="background-image:url(static/img/huang.png); "></div>
        </div>

        <div class="finger"></div>
        <div id="controlbox">
          <div id="control">
            <div class="tb">
              <div class="tbflag"></div>
              <div class="tbbg" style="background-image: url(static/img/heibai.png);"></div>

            </div>
            <div class="lr">
              <div class="lrflag"></div>
              <div class="lrbg" style=" background-image: url(static/img/huangbai.png);"></div>

            </div>
          </div>
        </div>
      </div>

    </div>
    <div class="dingshi tongyong">
      <div class="fr">
        <span class="switch-off" id="switch" @click="customswitch($event)" themecolor="#1989fa"></span><span id="trigger1" class="zhixiang">
                <div class="right"></div>
            </span>
      </div>
      <span class="wenzi">自定义休息<span>工作45分钟,休息10分钟,循环1次</span></span>
    </div>
    <div class="shuimian tongyong">
      <div class="fr">
            <span id="trigger3" class="zhixiang">
                <div class="right"></div>
            </span>
      </div>
      <span class="wenzi">助眠<span>10分钟</span></span>
    </div>
    <div class="qichuang tongyong">
      <div class="fr">
            <span id="trigger4" class="zhixiang">
                <div class="right"></div>
            </span>
      </div>
      <span class="wenzi">起床<span>3分钟</span></span>
    </div>
    <div class="menu">
      <div class="swiper-container" style="height: 100%">
        <div class="swiper-wrapper">

          <div class="swiper-slide kaiguan" alt="0" @click="onOff">
            <div class="yuan ">
              <span class="iconfont icon-kaiguan "></span>

            </div>
            <span>开关</span>
          </div>

          <div class="swiper-slide dimming" alt="3" @click="!dimmingFlag && tiaoguang()">
            <div class="yuan">
              <span class="iconfont icon-tiaoguang "></span>
            </div>
            <span>调光</span>
          </div>

          <div class="swiper-slide dimming" alt="1"  @click="!dimmingFlag && tiaoguang()">
            <div class="yuan">
              <!--<span class="iconfont icon-taiyang "></span>-->
              <span class="iconfont icon-tiaoguang "></span>
            </div>
            <span>调光</span>
          </div>

          <div class="swiper-slide night" alt="9" @click="!nightFlag && night()">
            <div class="yuan">
              <span class="iconfont icon-yedeng "></span>
            </div>
            <span>夜灯</span>
          </div>

          <div class="swiper-slide read" alt="5" @click="!readFlag && read()">
            <div class="yuan">
              <span class="iconfont icon-yuedu "></span>
            </div>
            <span>阅读</span>
          </div>

          <div class="swiper-slide intelligence" alt="11" @click="!intelligenceFlag &&　intelligence()">
            <div class="yuan">
              <span class="iconfont icon-zhinengtiaoguang "></span>
            </div>
            <span>智能调光</span>
          </div>





          <div class="swiper-slide read" alt="13" @click="!readFlag && read()">
            <div class="yuan">
              <span class="iconfont icon-yuedu "></span>
            </div>
            <span>阅读</span>
          </div>

          <div class="swiper-slide visit" alt="4" @click="!visitFlag && visit()">
            <div class="yuan">
              <span class="iconfont icon-huike "></span>
            </div>
            <span>会客</span>
          </div>

          <div class="swiper-slide movie" alt="6" @click="!movieFlag && movie()">
            <div class="yuan">
              <span class="iconfont icon-guanying "></span>
            </div>
            <span>观影</span>
          </div>

          <div class="swiper-slide pc" alt="8" @click="!pcFlag && pc()">
            <div class="yuan">
              <span class="iconfont icon-diannao "></span>
            </div>
            <span>电脑</span>
          </div>

          <div class="swiper-slide sleep" alt="10" @click="!sleepFlag && sleep(10)">
            <div class="yuan">
              <span class="iconfont icon-shuimian "></span>
            </div>
            <span>助眠</span>
          </div>

          <div class="swiper-slide wake" alt="12" @click="!wakeFlag && wake(3)">
            <div class="yuan">
              <span class="iconfont icon-jiaoxing"></span>
            </div>
            <span>起床</span>
          </div>

          <div class="swiper-slide" alt="2">
            <div class="yuan">
              <span class="iconfont icon-yueguang"></span>
            </div>
            <span>月光</span>
          </div>

          <div class="swiper-slide meal" alt="7" @click="!mealFlag && meal()">
            <div class="yuan">
              <span class="iconfont icon-jiucan "></span>
            </div>
            <span>就餐</span>
          </div>

          <!--<div class="swiper-slide" alt="12">
              <div class="yuan">
                  <span class="iconfont icon-zidingyi "></span>

              </div>
              <span>自定义休息</span>
          </div>-->
          <!--<div class="swiper-slide" alt="13">
              <div class="yuan">
                  <span class="iconfont icon-dingshi "></span>

              </div>
              <span>延时关灯</span>
          </div>-->

        </div>
        <div class="swiper-pagination"></div>
      </div>
    </div>
  </div>
</template>

<script>
  import UplusApi from '@/api/uplusapi.js';
  export default {
    name: "MainContent",
    data(){
      return{
        count:0,
        open: 0 ,//0是关灯，1是开灯，如果开灯，那么要付给一些按钮的active状态,-1 是离线
        setting:[],
        instance:{},
        devicemac:'',//设备mac地址
        onOffFlag:false,//电源开关
        dimmingFlag:false,//调光模式
        readFlag:false,//阅读模式
        pcFlag:false,//电脑模式
        nightFlag:false,//夜灯模式
        sleepFlag:false,//助眠模式
        sleepValue:'',//助眠剩余时长
        wakeFlag:false,//起床模式
        wakeValue:'',//起床剩余时间
        intelligenceFlag:false,//智能调光
        delayTimeFlag:false,//延时关机
        customRestFlag:false,//自定义休息功能模式
        customRestTimeValue:"10",//自定义休息时间
        customNumValue:"1",//自定义循环次数
        customWorkTimeValue:"45",//自定义工作时间
        brightness:'',
        //吸顶灯额外添加
        visitFlag:false,//会客模式
        movieFlag:false,//观影模式
        mealFlag:false,//就餐模式
        RGB:'',//灯光颜色
        xdimmingFlag:false,//吸顶灯的调光模式
        // devFlag:1,// 1表示台灯 ，2表示吸顶灯
        isShow:false
      }
    },
    mounted(){
      var backFlag=localStorage.name;
      if(backFlag!=null && backFlag.length>0){
        localStorage.clear();
        window.location.reload();
      }
      this.init();
      this.getUrlParams();
      eventBus.$on("opacity", (value) =>{
        this.brightness = value
        this.dimming();
      })
      eventBus.$on("color",(value)=>{
        this.RGB = value
        console.log("获取到的色温为："+value)
        this.color();
      })

    },
    methods:{
      toAbout(){
        this.$router.push("/aboutus");
        $("body").removeClass("lixian"); $("body").addClass("boot");
      },
      showMenu(){
          $(".xiala").show();
          $(".bg").show();
      },
      hideMenu(){
        $(".xiala").hide();
        $(".bg").hide();
      },
      reload(){
        console.log("进入reeload方法&reload方法open的状态是："+ this.open)
        if (this.open == "0") {
          //显示关灯状态
          this.button();
          $(".thetitle").html("设备已关闭");
          $("body").removeClass("lixian"); $("body").addClass("boot");
        } else if (this.open == "-1") {
          $(".thetitle").html("设备已离线");
          this.button();
          $(".swiper-slide").removeClass("active");
          $("body").addClass("lixian");
          $("body").removeClass("boot");
        }
        else {
          $("body").removeClass("lixian"); $("body").removeClass("boot");
          //开灯
          kaiji();
          this.button();
        }
      },
      button(){
        {
          //取得哪些按钮显示
          var blockArry = this.setting;
          //取得哪些按钮激活
          var activeArry = [];
          //处理按钮
          $(".swiper-slide").each(function () {
            var display = false;
            for (var i in blockArry) {
              if ($(this).attr("alt") == blockArry[i]) {
                if (activeArry.indexOf(blockArry[i]) != -1) {
                  $(this).addClass("active");
                  //jihuo($(this));
                }
                display = true;
              }
            }
            if (!display) {
              $(this).remove();
            }
          })
          //生成底部
          var swiper = new Swiper('.swiper-container', {
            slidesPerView: 4,
            spaceBetween: 0,
            slidesPerGroup: 4,
            loop: false,
            loopFillGroupWithBlank: true,
            pagination: {
              el: '.swiper-pagination',
              clickable: true,
            },
          });
        }
      },
      //电源开关
      async onOff(){
        console.log('开关进入');
        var this_ = this;
        this.onOffFlag = !this.onOffFlag;
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'onOffStatus', this.onOffFlag, true).then(function(ret){
          console.log(ret.retCode);
          if (ret.retCode === '000000' || ret.retCode === '00000') {
            //alert('开关命令下发');
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function (ret) {
              //alert(JSON.stringify(ret));
              console.log(ret);
            })
          }
        })
      },
      tiaoguang:function(){
        var this_ = this;
        this.dimmingFlag = !this.dimmingFlag;
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'dimmingStatus', this.dimmingFlag, true).then(function(ret){
          console.log('调光进入');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      read:function(){
        var this_ = this;
        this.readFlag=!this.readFlag;
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'readMode', this.readFlag, true).then(function(ret){
          console.log('阅读进入');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      pc:function(){
        var this_ = this;
        this.pcFlag=!this.pcFlag;
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'pcMode', this.pcFlag, true).then(function(ret){
          console.log('电脑模式');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      night:function(){
        var this_ = this;
        this.nightFlag=!this.nightFlag;
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'nightMode', true, true).then(function(ret){
          console.log('夜灯模式');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      //调光
      dimming(){
        var this_ = this;
        let value=parseInt(100*((this_.brightness-0.525)/(1-0.525)));
        if(value<5){
          value=5
        }
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'brightness' , value, true).then(function(ret){
          console.log('亮度调节');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      // 调色温
      color(){
        var this_ = this;
        let value=parseInt(100*this.RGB);
        console.log("处理后的色温为："+ value)
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'colorTempDegree' , value, true).then(function(ret){
          console.log('色温调节');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      intelligence(){
        var this_ = this;
        this.intelligenceFlag=!this.intelligenceFlag;
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'intelligenceStatus' , true, true).then(function(ret){
          console.log('进行智能调光');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      sleep(value){
        var this_ = this;
        this.sleepFlag=!this.sleepFlag;
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'sleepMode2' , value, true).then(function(ret){
          console.log('助眠模式');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      wake(value){
        var this_ = this;
        this.wakeFlag=!this.wakeFlag;
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'wakeMode2' , value, true).then(function(ret){
          console.log('起床模式');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      //以下是吸顶灯特有的功能
      //会客模式功能
      visit:function(){
        var this_ = this;
        this.visitFlag=!this.visitFlag;
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'visitingMode', this.visitFlag, true).then(function(ret){
          console.log('会客进入');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      //观影模式功能
      movie:function(){
        var this_ = this;
        this.movieFlag=!this.movieFlag;
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'movieMode', this.movieFlag, true).then(function(ret){
          console.log('观影进入');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      //就餐模式功能
      meal:function(){
        var this_ = this;
        this.mealFlag=!this.mealFlag;
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'mealMode', this.mealFlag, true).then(function(ret){
          console.log('就餐进入');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      delayTime(value){
        var this_ = this;
        this.delayTimeFlag=!this.delayTimeFlag;
        this.instance.logicEngineModule.calculatePromise(this.devicemac, 'delayTime' , value, true).then(function(ret){
          console.log('延时关机模式');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      //自定义工作时间
      customWorkTime(value){
        var this_ = this;
       return this.instance.logicEngineModule.calculatePromise(this.devicemac, 'customWorkTime' , value, true).then(function(ret){
          console.log('自定义工作时间模式');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      //自定义休息时间
      customRestTime(value){
        var this_ = this;
        return this.instance.logicEngineModule.calculatePromise(this.devicemac, 'customRestTime' , value, true).then(function(ret){
          console.log('自定义休息时间模式');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      //自定义循环次数
      customNum(value){
        var this_ = this;
        return  this.instance.logicEngineModule.calculatePromise(this.devicemac, 'customNum' , value, true).then(function(ret){
          console.log('自定义循环次数模式');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      //自定义休息开关
      customRest(value){
        var this_ = this;
       this.instance.logicEngineModule.calculatePromise(this.devicemac, 'customRestMode' , value, true).then(function(ret){
          console.log('自定义休息开关模式');
          if(ret.retCode === '00000' || ret.retCode === '000000') {
            this_.instance.logicEngineModule.operatePromise(this_.devicemac).then(function(ret){
              console.log(ret);
            })
          }
        })
      },
      async customswitch(event){
        let state=event.currentTarget.getAttribute("class");
        await this.customWorkTime(this.customWorkTimeValue);
        await this.customRestTime(this.customRestTimeValue);
        await this.customNum(this.customNumValue);
        if(state==="switch-off"){
          this.customRest(true);
        }else{
          this.customRest(false);
        }

      },
      //关闭容器
      deviceReady:function () {
        var this_ = this;
        this.instance.initDeviceReady().then(function () {
          if (this_.instance.deivceReady){
            this_.instance.closeH5ContainerView();
          }
        })
      },
      //获取devicemac
      getUrlParams:function(){
        var url = window.location.search;
        var query = {};
        if (url.indexOf('?') !== -1) {
          var str = url.substr(1);
          var strs = str.split('&');
          for (var i = 0; i < strs.length; i++) {
            query[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]);
          }
        }
        var hash = window.location.hash;
        if (hash.indexOf('?') !== -1) {
          var hashStr = hash.substr(hash.indexOf('?') + 1, hash.length);
          var hashArr = hashStr.split('&');
          for (var _i = 0; _i < hashArr.length; _i++) {
            query[hashArr[_i].split('=')[0]] = decodeURI(hashArr[_i].split('=')[1]);
          }
        }
        console.log('devicemac：'+query.devicemac);
        var mac = "http://uplus.haier.com/uplusapp/DeviceList/DeviceEditView.html?mac="+query.devicemac;
        $(".devicelist").attr("href", mac);
        this.devicemac = query.devicemac;
      },
      init(){
        var this_ = this;
        console.log('初始化')
        this.instance = new UplusApi();
        return this.instance.initDeviceReady().then(async function () {
          console.log('初始化状态'+this_.instance.deivceReady);
          if (this_.instance.deivceReady){
            await this_.getAttributes();
            await this_.attach();
            await this_.reload();
          }
        })
      },
      attach() {
        var this_ = this;
        // console.log('订阅设备');
        this.instance.logicEngineModule.getBaseInfoPromise(this.devicemac).then(function(data){
            this_.baseInfo=data.retData.connection;
        })
        this.instance.logicEngineModule.attachPromise(this.devicemac,function (mac, baseInfo, attributes, cautions) {
          console.log("这里是attach的baseInfo："+ this_.baseInfo)
            // .retData.connection
          /*console.log('设备mac', mac);
          console.log('设备基本信息', baseInfo);
          console.log('设备属性列表', attributes);
          console.log('设备报警列表', cautions);*/
          if(attributes && attributes.length){
            console.log('设备属性列表============', attributes);
            attributes.filter(function(att){
              if(this_.baseInfo == 'OFFLINE'){
                att.value = 'false';
              }else{
                //开关
                if (att.name === 'onOffStatus'){
                  if (att.value==='false'){
                    this_.onOffFlag = false;
                  }else if (att.value==='true') {
                    this_.onOffFlag = true;
                  }
                }
                //调光模式
                else if(att.name === 'dimmingStatus') {
                  if (att.value==='false'){
                    this_.dimmingFlag = false;
                  }else if (att.value==='true'){
                    this_.dimmingFlag = true;
                  }
                }
                //阅读模式
                else if(att.name === 'readMode') {
                  if (att.value==='false'){
                    this_.readFlag = false;
                  }else if (att.value==='true') {
                    this_.readFlag = true;
                  }
                }
                //电脑模式
                else if(att.name === 'pcMode') {
                  if (att.value==='false'){
                    this_.pcFlag = false;
                  }else if (att.value==='true') {
                    this_.pcFlag = true;
                  }
                }
                //夜灯模式
                else if(att.name === 'nightMode') {
                  if (att.value==='false'){
                    this_.nightFlag = false;
                  }else if (att.value==='true') {
                    this_.nightFlag = true;
                  }
                }
                //助眠模式
                else if(att.name === 'sleepMode2') {
                  this_.sleepValue=att.value;
                  if (att.value==='0'){
                    this_.sleepFlag = false;
                  }else{
                    this_.sleepFlag = true;
                  }
                }
                //起床模式
                else if(att.name === 'wakeMode2') {
                  this_.wakeValue=att.value;
                  if (att.value==='0'){
                    this_.wakeFlag = false;
                  }else {
                    this_.wakeFlag = true;
                  }
                }
                //智能调光
                else if(att.name === 'intelligenceStatus') {
                  if (att.value==='false'){
                    this_.intelligenceFlag = false;
                  }else if (att.value==='true'){
                    this_.intelligenceFlag = true;
                  }
                }
                //自定义休息功能模式
                else if(att.name === 'customRestMode') {
                  if (att.value==='false'){
                    this_.customRestFlag = false;
                  }else if (att.value==='true'){
                    this_.customRestFlag = true;
                  }
                }
                //会客模式
                else if(att.name === 'visitingMode') {
                  if (att.value==='false'){
                    this_.visitFlag = false;
                  }else if (att.value==='true'){
                    this_.visitFlag = true;
                  }
                }
                //观影模式
                else if(att.name === 'movieMode') {
                  if (att.value==='false'){
                    this_.movieFlag = false;
                  }else if (att.value==='true'){
                    this_.movieFlag = true;
                  }
                }
                //就餐模式
                else if(att.name === 'mealMode') {
                  if (att.value==='false'){
                    this_.mealFlag = false;
                  }else if (att.value==='true'){
                    this_.mealFlag = true;
                  }
                }
              }

            })
          }

        }).then(function(ret) {
          // console.log('订阅设备'+ret);
        })
      },
      //获取设备属性
      getAttributes() {
        var this_ = this;
        console.log('获取设备属性');
        this.instance.logicEngineModule.getBaseInfoPromise(this.devicemac).then(function(baseInfo){
          console.log('########基本信息#########');
          console.log(baseInfo);
          if (baseInfo.retData.connection=="OFFLINE") {
            console.log("我这里显示设备的状态" + baseInfo.retData.connection);
            this_.open= -1;
          }
        });
        this.instance.logicEngineModule.getAttributeListPromise(this.devicemac).then(function(attributes){
          console.log('########设备属性#########');
          console.log(attributes);
          const attArr = attributes.retData;
          for(let i=0;i  < attArr.length;i++){
            console.log(attArr[i]);
          }
          let setting=[];
          var devDimming =3 ;
          var devRead = 5;

          attArr.filter(function(att) {
            //判断设备
            var isLamp=setting.indexOf(7);
            console.log("如果不为-1则判定为吸顶灯:"+ isLamp);
              if(isLamp!= -1){
              devDimming = 1;
              devRead = 13;
            }
            // console.log("这里的调光使用的是第"+ devDimming +"号，阅读使用的是第"+ devRead +"号");
            //助眠
            if(att.name === 'sleepMode2') {
              setting.push(10)
              new MobileSelect({
                trigger: '#trigger3',
                title: '助眠定时',
                wheels: [{ data: ['5分钟','10分钟', '15分钟', '30分钟', '40分钟', '50分钟', '60分钟', '70分钟', '80分钟', '90分钟', '100分钟', '120分钟'] }
                ],
                triggerDisplayData: false,
                position: [0],
                transitionEnd: function (indexArr, data) {
                },
                callback: function (indexArr, data) {
                  $(".shuimian >.wenzi>span").html(data[0])
                  this_.sleep( parseInt(data[0]));
                }
              });
            } else if(att.name === 'wakeMode2'){
              setting.push(12)
              new MobileSelect({
                trigger: '#trigger4',
                title: '唤醒时长',
                wheels: [{ data: ['1分钟', '2分钟', '3分钟', '4分钟', '5分钟'] }
                ],
                triggerDisplayData: false,
                position: [0],
                transitionEnd: function (indexArr, data) {
                },
                callback: function (indexArr, data) {
                  $(".qichuang >.wenzi>span").html(data[0])
                  this_.wake( parseInt(data[0]));
                }
              });
            }
            else if(att.name === 'delayTime'){
              new MobileSelect({
                trigger: '#trigger2',
                title: '延时关灯',
                wheels: [{ data: ['5分钟','10分钟', '15分钟', '30分钟', '40分钟', '50分钟', '60分钟', '70分钟', '80分钟', '90分钟', '100分钟', '120分钟'] }
                ],
                triggerDisplayData: false,
                flag: 0,
                position: [1],
                callback: function (indexArr, data) {
                  let value = parseInt(data[0]);
                  this_.delayTime(value)
                }//初始化定位 两个轮子都选中在索引1的选项
              });
            }//自定义休息
            else if(att.name === 'customRestMode'){
              new MobileSelect({ trigger: '#trigger1',
                title: '自定义休息',
                wheels: [
                  { data: ['30分钟', '45分钟', '60分钟', '90分钟'] },
                  { data: ['10分钟', '15分钟', '20分钟', '30分钟'] },
                  { data: ['1次', '2次', '3次', '4次'] }
                ],
                triggerDisplayData: false,
                flag: 1,
                position: [1, 0, 0],
                callback: function (indexArr, data) {
                  this_.customNumValue=parseInt(data[2])
                  this_.customWorkTimeValue=parseInt(data[0])
                  this_.customRestTimeValue=parseInt(data[1])
                  $(".dingshi >.wenzi>span").html("工作" + data[0] + ",休息" + data[1] + ",循环" + data[2])
                }//初始化定位 两个轮子都选中在索引1的选项
              });
            }

            //开关
            else if (att.name === 'onOffStatus'){
              setting.push(0)
            }
            //就餐模式并且进行判断
            else if(att.name=== 'mealMode'){
              setting.push(7)
            }
            //调光模式
            else if(att.name === 'dimmingStatus') {
              setting.push(devDimming)
            }
            //阅读模式
            else if(att.name === 'readMode') {
              setting.push(devRead)
            }
            //电脑模式
            else if(att.name === 'pcMode') {
              setting.push(8)
            }
            //夜灯模式
            else if(att.name === 'nightMode') {
              setting.push(9)
            }
            //会客模式
            else if(att.name ==='visitingMode'){
              setting.push(4)
            }
            //观影模式
            else if(att.name === 'movieMode'){
              setting.push(6)
            }
           /* //助眠模式
            else if(att.name === 'sleepMode2') {
              setting.push(10)
            }*/
            //起床模式
            /*else if(att.name === 'wakeMode2') {
              setting.push(11)
            }*/
            //智能调光
            else if(att.name === 'intelligenceStatus') {
              setting.push(11)
            }
          })
          this_.setting=setting
        });

      },
    },
    watch:{
      //监测开关状态
      onOffFlag:function (val) {
        console.log('开关状态'+val)
        if (!val){
          guanji();
        }else if (val) {
          kaiji();
        }
      },
      dimmingFlag:function (val) {
        console.log('调光状态'+val)
        if (!val){
          guanbi($(".dimming"));
        }else if (val) {
          jihuo($(".dimming"));
        }
      },
      readFlag:function (val) {
        console.log('阅读状态'+val)
        if (!val){
          guanbi($(".read"));
        }else if (val) {
          jihuo($(".read"));
        }
      },
      pcFlag:function (val) {
        console.log('电脑状态'+val)
        if (!val){
          guanbi($(".pc"));
        }else if (val) {
          jihuo($(".pc"));
        }
      },
      nightFlag:function (val) {
        console.log('夜灯状态'+val)
        if (!val){
          guanbi($(".night"));
        }else if (val) {
          jihuo($(".night"));
        }
      },
      intelligenceFlag:function (val) {
        console.log('智能调光状态'+val)
        if (!val){
          guanbi($(".intelligence"));
        }else if (val) {
          jihuo($(".intelligence"));
        }
      },
      sleepFlag:function (val) {
        console.log('助眠状态'+val)
        if (!val){
          guanbi($(".sleep"));
        }else if (val) {
          jihuo($(".sleep"));
        }
      },
      wakeFlag:function (val) {
        console.log('起床状态'+val)
        if (!val){
          guanbi($(".wake"));
        }else if (val) {
          jihuo($(".wake"));
        }
      },
      delayTimeFlag:function(val){
        console.log('延时关灯状态'+val)
        if (!val){
          guanji();
        }
      },
      customRestFlag:function(val){
        if(!val){
          honeySwitch.showOff($("#switch"));
        }else if(val){
          honeySwitch.showOn($("#switch"))
        }
      },
      visitFlag:function (val) {
        console.log('会客状态'+val)
        if (!val){
          guanbi($(".visit"));
        }else if (val) {
          jihuo($(".visit"));
        }
      },
      movieFlag:function (val) {
        console.log('观影状态'+val)
        if (!val){
          guanbi($(".movie"));
        }else if (val) {
          jihuo($(".movie"));
        }
      },
      mealFlag:function (val) {
        console.log('就餐状态'+val)
        if (!val){
          guanbi($(".meal"));
        }else if (val) {
          jihuo($(".meal"));
        }
      },
      dimmingFlag:function (val) {
        console.log('调光状态'+val)
        if (!val){
          guanbi($(".dimming"));
        }else if (val) {
          jihuo($(".dimming"));
        }
      },
      wakeValue:function(val){
        $(".qichuang >.wenzi>span").html(val+"分钟")
      },//唤醒时长变化时触发
      sleepValue:function(val){
        $(".shuimian >.wenzi>span").html(val+"分钟")
      },//助眠时长变化时触发
    }
  }
</script>

<style scoped>

</style>
